﻿namespace Borg.AttributeAnalyze.Result
{
    public class MissingHandler : ResultBase
    {
        private readonly ExtensionTypeInfo _extension;
        
        protected readonly string Handler;
        protected readonly string ImplementingMethod;
        
        private readonly PlugTypeInfo _plug;
        private readonly SlotTypeInfo _slot;
        private readonly SlotDefinition _slotDefinition;

        public MissingHandler(ExtensionTypeInfo extension, string handler, string implementingMethod)
            : base(extension.Assembly, Component.Extension, ResultType.MissingHandler, extension, extension)
        {
            _extension = extension;
            RepositoryElement = extension;
            ExtensionTypeInfo = extension;
            Handler = handler;
            ImplementingMethod = implementingMethod;
        }

        public MissingHandler(PlugTypeInfo plug, string handler, string implementingMethod)
            : base(plug.Assembly, Component.Plug, ResultType.MissingHandler, plug, plug.ExtensionTypeInfo)
        {
            _slotDefinition = plug.slotDefinition;
            _plug = plug;
            RepositoryElement = plug;
            ExtensionTypeInfo = plug.ExtensionTypeInfo;
            Handler = handler;
            ImplementingMethod = implementingMethod;
        }

        public MissingHandler(SlotTypeInfo slot, string handler, string implementingMethod)
            : base(slot.Assembly, Component.Slot, ResultType.MissingHandler, slot, slot.ExtensionTypeInfo)
        {
            _slotDefinition = slot.slotDefinition;
            _slot = slot;
            RepositoryElement = slot;
            ExtensionTypeInfo = slot.ExtensionTypeInfo;
            Handler = handler;
            ImplementingMethod = implementingMethod;
        }

        public override string ToMsBuildMessageString()
        {
            return string.Format(
                "handler not implemented\n{0}method: {1}\n{0}handler: {2}\n{0}class: {3}",
                new object[] { GetWhiteSpace(2), ImplementingMethod, Handler, TypeName });
        }

        public override MessageType MessageType
        {
            get { return MessageType.Error; }
        }
    }
}

